<template>
  <!--费率设置-->
  <div class="statistics-container">
    <vab-query-form>
      <vab-query-form-right-panel :span="50">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.keyword"
              style="margin-right: 10px"
              placeholder="请输入用户名或手机号"
              clearable
            />
          </el-form-item>
          <!-- <el-form-item>
            <el-select
              v-model="form.status"
              clearable
              placeholder="请选择类型"
              @change="selectStatus()"
            >
              <el-option
                v-for="item in status"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item> -->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="search">
              查询
            </el-button>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-refresh-right"
              @click="restart"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      @selection-change="setSelectRows"
    >
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="序号"
        sortable
        type="index"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="login_phone_number"
        label="登录手机号"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="company_name"
        label="公司名称"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="pay_phone_number"
        label="收支付手机号"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="channel_from"
        label="渠道商"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="channel_from"
        label="渠道商"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="status"
        label="账号类型"
      >
        <template #default="{ row }">
          {{ row.status == 1 ? '传媒公司' : row.status == 2 ? '地产公司' : '' }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="region"
        label="地区"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="create_time"
        label="创建日期"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="ratio[0].ratio"
        label="京灵小额费率%"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="ratio[1].ratio"
        label="京灵大额费率%"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="ratio[2].ratio"
        label="猪小税普票费率%"
      />
      <el-table-column align="center" label="操作">
        <template #default="{ row }">
          <el-button type="text" @click="edit(row)">修改费率</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 弹窗 -->
    <el-dialog
      title="选择修改类型"
      :visible.sync="dialogFormVisible"
      width="30%"
    >
      <el-button type="primary" size="mini" @click="addone()">
        京灵小额专票%
      </el-button>
      <el-button type="primary" size="mini" @click="addtwo()">
        京灵大额专票%
      </el-button>
      <el-button type="success" size="mini" @click="addthree()">
        猪小税普票%
      </el-button>
    </el-dialog>
    <el-dialog :title="tit" :visible.sync="dialogEdit">
      <el-input v-model="number" clearable />
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogEdit = false">取 消</el-button>
        <el-button type="primary" @click="addtax()">确 定</el-button>
      </div>
    </el-dialog>

    <el-pagination
      background
      :current-page="queryForm.page"
      :page-size="queryForm.list_row"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
  import { getCompanyRatioLists, editCompanyRatios } from '@/api/common'

  export default {
    name: 'Rate',
    data() {
      return {
        status: [
          { value: 1, label: '未完成设置' },
          { value: 2, label: '已完成设置' },
        ],
        queryForm: {
          page: 1,
          list_row: 10,
          keyword: '',
        },
        form: {
          content: '',
        },
        disabled: false,
        listLoading: false,
        list: [],
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        dialogFormVisible: false,
        dialogEdit: false,
        tit: '',
        taxid: '',
        type: '',
        number: '',
      }
    },
    created() {
      this.getData()
    },
    methods: {
      handleDetail() {},
      //搜索
      search() {
        this.getData()
      },
      restart() {
        this.queryForm = []
        this.getData()
      },
      getData() {
        let params = {
          page: this.queryForm.page,
          limit: this.queryForm.list_row,
          search_input: this.queryForm.keyword,
        }
        getCompanyRatioLists(params).then((data) => {
          this.list = data.data
          this.total = data.count
        })
      },
      edit(row) {
        this.dialogFormVisible = true
        this.taxid = row.id
      },
      addone() {
        this.dialogEdit = true
        this.tit = '京灵小额专票%'
        this.type = 1
      },
      addtwo() {
        this.dialogEdit = true
        this.tit = '京灵大额专票%'
        this.type = 2
      },
      addthree() {
        this.dialogEdit = true
        this.tit = '猪小税普票%'
        this.type = 3
      },
      addtax() {
        let params = {
          id: this.taxid,
          type: this.type,
          ratio: this.number,
        }
        editCompanyRatios(params).then((data) => {
          this.$message.success('修改成功！')
          this.dialogEdit = false
          this.dialogFormVisible = false
          this.getData()
        })
      },
      setSelectRows() {},
      handleSizeChange(val) {
        this.queryForm.list_row = val
        this.getData()
      },
      handleCurrentChange(val) {
        this.queryForm.page = val
        this.getData()
      },
      selectStatus(e) {
        this.queryForm.types === e.value
      },
    },
  }
</script>

<style lang="scss" scoped>
  .el-button {
    font-size: 14px;
  }
</style>
